import { CommonModal } from "@/views/components/CommonModal";
import { Alert, Popconfirm, message, Space } from "antd";
import { useEffect, useState } from "react";
import { SearchSimpleTable } from "@/views/components/SearchTable/index";
import { useTableConfig } from "@/views/components/SearchTable/hooks/useTableConfig";
import { deleteGoodsSkuLog, getGoodsSkuLogList } from "@/pages/GoodsModule/systemGoods/service";
import moment from "moment";

function GoodsList(props) {
	const { title, record, onCancel } = props;
	const columns = [
		{
			name: "序号",
			code: "name",
			width: 60,
			render(text, record, index) {
				return index + 1;
			}
		},
		{
			name: "开始时间",
			code: "createTime",
			render: text => (text ? <div>{moment(text).format("YYYY-MM-DD HH:mm:ss")}</div> : ""),
			key: "createTime",
			width: 180
		},
		{
			name: "截止时间",
			code: "endTime",
			render: text => (text ? <div>{moment(text).format("YYYY-MM-DD HH:mm:ss")}</div> : ""),
			key: "endTime",
			width: 180
		},
		{
			name: title,
			code: "oldPrice",
			key: "oldPrice",
			width: 120
		},
		{
			name: "备注",
			code: "note",
			key: "note",
			// render: text => (text ? <div>.split(separator)</div> : ""),
			width: 180
		},
		{
			title: "操作",
			code: "opera",
			key: "opera",
			width: 80,
			render: (t, r, i) => (
				<span className="opera-span-common">
					<Popconfirm title="确定删除该条数据?" onConfirm={() => confirm(r)}>
						<a href="#" disabled={r.isDefault == 0}>
							删除
						</a>
					</Popconfirm>
				</span>
			)
		}
	];
	const confirm = async item => {
		deleteGoodsSkuLog({ id: item.id }).then(res => {
			const { success, msg } = res;
			if (success) {
				message.success(msg);
				fetchList();
			}
		});
	};

	const tableKey = "HistoryPriceModal2331";
	const tableRequest = getGoodsSkuLogList;

	const { selectedKeys, selectedRows, dataSource, fetchList, query, searchSimpleTableProps } = useTableConfig({
		tableKey,
		rowKey: "id",
		columns,
		tableRequest,
		autoFetch: false,
		hasPagination: true,
		hasQuickSearch: false,
		columnResize: true,
		beforeQuerySearch: ({ API_DATA }) => {
			return {
				...API_DATA,
				id: record.id,
				type: title == "成本价" ? 1 : 2
			};
		},
		resetSourceData: false,
		hasColsSetting: false,
		hasToggleSearchForm: false
	});
	useEffect(() => {
		fetchList();
	}, []);
	return <SearchSimpleTable key={tableKey} {...searchSimpleTableProps} />;
}
useEffect;
/** 未匹配商品明细 */
function HistoryPriceModal(props) {
	const { title, record, onCancel } = props;
	function handleOk() {
		onCancel;
	}

	return (
		<CommonModal
			title={{ title: "查看历史" + title }}
			className="views-table-dialog"
			open={true}
			width="1000px"
			onOk={handleOk}
			onCancel={props.onCancel}
		>
			<GoodsList {...props} />
		</CommonModal>
	);
}

export default HistoryPriceModal;
